package com.tanger.common.jpa;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.util.Objects;

/**
 * @Description 基础实体类
 * @Author Hchenbin
 * @Date 2022/6/24 10:30
 * @Version 1.0
 */
@ApiModel("基础实体类")
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseEntity implements Serializable{

    @CreatedDate
    @Column(columnDefinition = "bigint(20) NOT NULL COMMENT '创建时间'")
    @ApiModelProperty("创建时间")
    private Long createTime;

    @LastModifiedDate
    @ApiModelProperty("更新时间")
    @Column(columnDefinition = "bigint(20) NOT NULL COMMENT '修改时间'")
    private Long updateTime;

    public Long getCreateTime() {
        return createTime;
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BaseEntity that = (BaseEntity) o;
        return Objects.equals(createTime, that.createTime) && Objects.equals(updateTime, that.updateTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(createTime, updateTime);
    }
}
